package com.itsc.dao;

import java.util.List;

import org.hibernate.Query;

import com.itsc.entities.User;
import com.opensymphony.xwork2.ActionContext;

@SuppressWarnings("unchecked")
public class LoginDao extends BaseDao<User>{

	public Boolean checkUser(String name, String password){
		
		String hql = "from User where user_name=? and user_pwd=?";
		Query query = getSession().createQuery(hql);
		query.setString(0, name);
		query.setString(1, password);
		List<User> list = query.list();
		if(list.size()!=0){
			return true;
		}else{
			return false;
		}
	}
	
	public User QueryUser(String name, String password) {
		String hql = "from User where user_name=? and user_pwd=?";
		Query query = getSession().createQuery(hql);
		query.setString(0, name);
		query.setString(1, password);
		List<User> list = query.list();
		if(list.size()!=0){
			return list.get(0);
		}else{
			return null;
		}
	}
	
	public Boolean checkCode(String code) {
		// TODO Auto-generated method stub
		boolean flag = false;
		String recode = (String) ActionContext.getContext().
				getSession().get("securityCode");
		if(code!=null&&!code.equals("")&&!recode.equals("")&&
				recode!=null&&code.equals(recode)){
			flag = true;
		}
		return flag;
	}
}
